<?php


namespace app\api\controller;

use app\facade\Basic;
use think\Request;
use app\api\service\Users as ServiceUsers;

class Users extends BaseController
{

    /**
     *  获取用户基本信息
    */
    public function information(Request $request)
    {
        $param['id'] = $request->user_id;
        $param['user_id'] = $request->user_id;

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->information($param);

        return Basic::json($result);
    }


    /**
     *  用户仪表盘
    */
    public function dashboard(Request $request)
    {
        $param['id'] = $request->user_id;

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->dashboard($param);

        return Basic::json($result);
    }

    /**
     *  获取用户基本信息
    */
    public function info(Request $request)
    {

        $param['id'] = $request->user_id;
        //$param['type'] = $request->type;

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->info($param);

        return Basic::json($result);
    }

    /**
     *  更新基础信息
    */
    public function updateInfo(Request $request)
    {

        $param['id'] = $request->user_id;

        $param['nickname'] = $request->param('nickname',null);
//        $param['country_id'] = $request->param('country_id',null);
//        $param['avatar_id'] = $request->param('avatar_id',null);

        /* 验证 */
        $this->validateData($param,'User.updateInfo');

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->setInfo($param);

        return Basic::json($result);

    }

    /**
     *  更新手机号
    */
    public function updatePhone(Request $request)
    {
        $param['id'] = $request->user_id;
        $param['phone_code'] = $request->param('phone_code','');
        $param['phone'] = $request->param('phone','');
        $param['code'] = $request->param('code','');

        /* 验证 */
        $this->validateData($param,'User.updatePhone');


        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->updatePhone($param);

        return Basic::json($result);
    }

    /**
     *  更新邮箱
    */
    public function updateEmail(Request $request)
    {
        $param['id'] = $request->user_id;
        $param['email'] = $request->param('email','');
        $param['code'] = $request->param('code','');

        /* 验证 */
        $this->validateData($param,'User.updateEmail');

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->updateEmail($param);

        return Basic::json($result);
    }


    /**
     *  更新密码
    */
    public function updatePassword(Request $request)
    {
        $param['id'] = $request->user_id;
        $param['token'] = $request->token;
        $param['password'] = $request->param('password','');
        $param['new_password'] = $request->param('new_password','');
        $param['repeat_password'] = $request->param('repeat_password','');

        /* 验证 */
        $this->validateData($param,'User.updatePassword');

        $serviceRetrieve = new ServiceUsers();
        $result = $serviceRetrieve->updatePassword($param);

        return Basic::json($result);
    }






}
